package Eyjafjalla.action;

import Eyjafjalla.effect.FireStanceEffect;
import Eyjafjalla.modcore.EyjafjallaMod;
import Eyjafjalla.monster.LTTQB;
import Eyjafjalla.monster.Pompeii;
import Eyjafjalla.monster.TQB;
import Eyjafjalla.patch.PompeiiPatch;
import com.badlogic.gdx.Gdx;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.IntentFlashAction;
import com.megacrit.cardcrawl.actions.common.RollMoveAction;
import com.megacrit.cardcrawl.actions.common.ShowMoveNameAction;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.relics.AbstractRelic;

import java.util.ArrayList;
import java.util.Iterator;

public class PompeiiAction extends AbstractGameAction {
    public PompeiiAction(){
        this.duration = startDuration = 1.2F;
        actionType = ActionType.SPECIAL;
        effectTimer = 0.1F;
        soundTimer = 0.2F;
        effectTimes = 0;
    }
    float soundTimer;
    float effectTimer;
    float effectTimes;
    boolean summoned = false;
    AbstractMonster pompeii = null;

    private void effectIt(){
        float blv = (float) Settings.HEIGHT / (float) Settings.WIDTH;
        float distance = 50F*Settings.scale;
        AbstractDungeon.effectsQueue.add(new FireStanceEffect(distance *(effectTimes-1),distance * blv,Settings.WIDTH + distance,Settings.HEIGHT + (1-effectTimes*2)*distance*blv));
        AbstractDungeon.effectsQueue.add(new FireStanceEffect(Settings.WIDTH + distance*(1-effectTimes),distance * blv, -distance,Settings.HEIGHT + (1-effectTimes*2)*distance*blv));
        AbstractDungeon.effectsQueue.add(new FireStanceEffect(distance *(effectTimes-1),distance * blv,Settings.WIDTH/2F,Settings.HEIGHT + (1-effectTimes*2)*distance*blv));
        AbstractDungeon.effectsQueue.add(new FireStanceEffect(Settings.WIDTH + distance*(1-effectTimes),distance * blv, Settings.WIDTH/2F,Settings.HEIGHT + (1-effectTimes*2)*distance*blv));
        effectTimes++;
    }

    private void soundIt(){
        CardCrawlGame.sound.playA("ATTACK_FIRE", 0.3F);
    }

    @Override
    public void update() {
        if(startDuration == duration){
            PompeiiPatch.facePompeii = true;
            effectIt();
            soundIt();
        }
        tickDuration();
        float delta = Gdx.graphics.getDeltaTime();
        effectTimer -= delta;
        if(effectTimer<=0F){
            effectTimer = 0.1F;
            effectIt();
        }
        soundTimer -= delta;
        if(soundTimer<=0F){
            soundTimer = 0.2F;
            soundIt();
        }

        if(duration<=0.3F&&!summoned){
            pompeii = new Pompeii(0F,0F);
            pompeii.init();
            pompeii.applyPowers();
            AbstractDungeon.getMonsters().monsters.clear();
            AbstractDungeon.getMonsters().addMonster(0,pompeii);
            Iterator var3 = AbstractDungeon.player.relics.iterator();
            while(var3.hasNext()) {
                AbstractRelic r = (AbstractRelic)var3.next();
                r.onSpawnMonster(pompeii);
            }
            summoned = true;
        }


        if(this.isDone){
            EyjafjallaMod.logSomething("=== Pompeii take turn ===");
            pompeii.showHealthBar();
            pompeii.usePreBattleAction();
        }
    }
}
